package com.example.roadship;

import java.util.ArrayList;
import java.util.HashMap;

import org.ksoap2.serialization.PropertyInfo;

import class_sources.ListItems.RankDetail;
import class_sources.EntryAdapter;
import class_sources.OtherMethods;
import class_sources.WSandJson;
import class_sources.ListItems.Item;
import class_sources.ListItems.SearchResultEntryItem;

import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.util.Log;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class RankDetailed extends ListActivity {
	
	private WSandJson wsHelper=new WSandJson();
	private String result,name;
	private ArrayList<Item> items = new ArrayList<Item>();
	private HashMap<String, String> user;
	private static String nameSpace="urn:ProductsService",url="http://www.codediary.net/service/roadship_service.php";
	SearchResultEntryItem si=new SearchResultEntryItem();
	private ArrayList<HashMap<String, String>> arrayList=new ArrayList<HashMap<String,String>>();
	private TextView username;
	private TextView comment;
	private RankDetail rankdetail;
	private EntryAdapter adapter;
	private static ArrayList<HashMap<String, String>> searchResult;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.activity_rank_detailed);	
		RankDetailed.searchResult=SearchActivity.searchResult;
		 PropertyInfo[] p= new PropertyInfo[1];
	        p[0]=new PropertyInfo();
	        p[0].setType(String.class);
	        p[0].setName("session");
	        p[0].setValue(searchResult.get(0).get("Session"));
		
      
	        result=wsHelper.CallWSFunction(nameSpace, url, "getRank", "urn:User#getRank", p);
	        arrayList=wsHelper.JsonToArrayList(result);
	        for (int i = 0; i < arrayList.size(); i++) {
	        	String name= arrayList.get(i).get("UserName").toString()+"  "+arrayList.get(i).get("UserSurname").toString();
	        	String comment=arrayList.get(i).get("COMMENT").toString();
	        	String rank=arrayList.get(i).get("Rank").toString();
	        	items.add(new RankDetail(name,comment,rank));
	        	
			}
	        adapter = new EntryAdapter(RankDetailed.this, items,false,null);
	        setListAdapter(adapter);
	      
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_rank_detailed, menu);
		return true;
		
	}

}
